﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;

namespace XDLogonMonitor {
    class Database {
        private long _EventNum = 0;

        public long EventNum {
            get { return _EventNum; } 
        }

        /// <summary>
        /// Assigns the EventNumber to the number of ticks, so it will always be unique.
        /// </summary>
        public Database() {
            _EventNum = DateTime.Now.Ticks;
        }
        public Database(long __EventNum) {
            _EventNum = __EventNum;
        }
        public Boolean AddEventRow(Int16 eventType, DateTime eventTime, String computerName) {
            try {
                LogonTimeDataSetTableAdapters.EventsTableAdapter eventsTableAdapater = new XDLogonMonitor.LogonTimeDataSetTableAdapters.EventsTableAdapter();
                int id = eventsTableAdapater.Insert(_EventNum, eventType, eventTime, computerName);
            }
            catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                return false;
            }
            return true;
        }
        public Boolean AddEventRow(long EventNum, Int16 eventType, DateTime eventTime, String computerName) {
            try {
                LogonTimeDataSetTableAdapters.EventsTableAdapter eventsTableAdapater = new XDLogonMonitor.LogonTimeDataSetTableAdapters.EventsTableAdapter();
                int id = eventsTableAdapater.Insert(EventNum, eventType, eventTime, computerName);
            }
            catch (Exception e) {
                Console.Error.WriteLine(e.Message);
                return false;
            }
            return true;
        }
    }
}
